package com.authManager.web.conf;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.authManager.web.interceptor.BaseInterceptor;
import com.authManager.web.interceptor.LogInterceptor;

/**
 * 说明：
 * 
 * @author: 小旋风
 */
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
	
	private static final Logger log = LoggerFactory.getLogger(WebConfiguration.class);
	@Autowired
	BaseInterceptor baseInterceptor;
	@Autowired
	LogInterceptor logInterceptor;

	/**
	 * 添加拦截器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		log.info("begin-拦截器");
		registry.addInterceptor(baseInterceptor);
		// 日志
		registry.addInterceptor(logInterceptor);
		log.info("end-拦截器");
	}

//	@Override
//	public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
//		log.info("走了：" + this.getClass() + " extendMessageConverters");
//		GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
//		gsonHttpMessageConverter.setGson(new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create());
//		MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
//		/***
//		 * 头格式
//		 */
//		List<MediaType> supportedMediaTypes = new ArrayList<>();
//		supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
//		supportedMediaTypes.add(MediaType.TEXT_HTML);
//		supportedMediaTypes.add(MediaType.TEXT_PLAIN);
//		mappingJackson2HttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
//
//		/***
//		 * 日期格式化,解决返回的日期类型格式化
//		 */
//		ObjectMapper objectMapper = mappingJackson2HttpMessageConverter.getObjectMapper();
//		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		objectMapper.setDateFormat(dateFormat);
//		mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
//		converters.add(mappingJackson2HttpMessageConverter); // 添加GsonHttpMessageConverter
//	}
}
